/**
 * 
 */
package due.pc.pcshoot.control;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.opengl.texture.Texture;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.region.TextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;
import org.anddev.andengine.opengl.vertex.RectangleVertexBuffer;

import android.content.Context;

/**
 * @author manhhung.vu
 *
 */
public class Arrow extends AnimatedSprite 
{
	//===============================================================/
	//Constants
	//===============================================================/
	public static final int DIRECTION_LEFT = 0;
	public static final int DIRECTION_RIGHT = 1;
	public static final int DIRECTION_TOP = 2;
	public static final int DIRECTION_BOTTOM = 3;
	
	public static final int ARROW_WIDTH = 32;
	public static final int ARROW_HEIGHT = 32;
	
	public static final float ALPHA = 0.2f;
	
	public static final String ARROWLEFT_IMAGEPATH = "gfx/pfeil_links_tiled.png";
	
	//===============================================================/
	//Fields
	//===============================================================/
	private boolean mActive = false;
	private int mDirection;
	
	
	//===============================================================/
	//Constructors
	//===============================================================/
	private Arrow(
			float pX, float pY, float pWidth, float pHeight, int pDirection,
			TiledTextureRegion pTiledTextureRegion) 
	{
		super(pX, pY, pWidth, pHeight, pTiledTextureRegion);
		showInaktiv();
		mDirection = pDirection;
	}
	
	
	//===============================================================/
	//Inherited Methods
	//===============================================================/
	
	
	
	//===============================================================/
	//Methods
	//===============================================================/
	private void showInaktiv() {
		animate(new long[]{1000, 1000}, 0, 1, false);
	}
	
	private void showAktiv() {
		animate(new long[]{100, 300}, 2, 3, true);
	}
	
	//===============================================================/
	//Getters & Setters
	//===============================================================/
	public boolean isActive() {
		return mActive;
	}
	
	public void setActive(boolean pActive) {
		mActive = pActive;
		if (mActive) showAktiv();
		else showInaktiv();
	}
	
	public int getDirection() {
		return mDirection;
	}
	
	public void setDirection(int pDirection) {
		this.mDirection = pDirection;
	}
	
	//===============================================================/
	//Static
	//===============================================================/
	public static Arrow createArrow(float pX, float pY, int pDirection, Engine pEngine, Context pContext)
	{
		Texture arrowleftTexture = new Texture(256, 64, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		TiledTextureRegion arrowleftTiledTextureRegion = TextureRegionFactory.createTiledFromAsset(
				arrowleftTexture, pContext, ARROWLEFT_IMAGEPATH, 0, 0, 4, 1);
		pEngine.getTextureManager().loadTexture(arrowleftTexture);
		
		Arrow arrow = new Arrow(pX, pY, ARROW_WIDTH, ARROW_HEIGHT, pDirection ,arrowleftTiledTextureRegion);
		arrow.setAlpha(ALPHA);
		
		switch (pDirection) {
		case DIRECTION_RIGHT:
			arrow.setRotation(180);
			break;
		case DIRECTION_TOP:
			arrow.setRotation(90);
			break;
		case DIRECTION_BOTTOM:
			arrow.setRotation(-90);
		}
		
		return arrow;
	}
	
}
